<?php


class WSB_XT_Pio_Model_Row extends WSB_Lib_Db_Row
{

	/**
	 * @return string
	 */
	protected $_configPath = 'WSB/XT/Pio/Model/form.config';

	/**
	 * @return string
	 */
	public function getTitle()
	{
	    return $this->custom_id;
	}

	/**
	 * @return array
	 */
	public function getFigures()
	{
		//$filePath = Zend_Registry::get('Zend_Config')->file->filePath;
		$figures = array();
		foreach(WSB_Lib_Div::csvToArray($this->figures, ',') AS $figure) {
			//$figures[] = $filePath . $figure;
			$figures[] = $figure;
		}
		return $figures;
	}

	/**
	 * @return array
	 */
	public function getCaptions()
	{
		return WSB_Lib_Div::csvToArray($this->captions, "\n");
	}

	/**
	 * @param integer $index
	 * @return string
	 */
	public function getCaption($index)
	{
		$captions = $this->getCaptions();
		$caption = isset($captions[$index]) ? $captions[$index] : '';
		return $this->_replaceSymbols($caption);
	}

	/**
	 * @return string
	 */
	public function getFulltext()
	{
		return $this->_replaceSymbols($this->fulltext);
	}

	/**
	 * @param string $str
	 * @return string
	 */
	private function _replaceSymbols($str)
	{
		$replacements = array(
			'#circle1#' => $this->_buildSymbolImgTag('circle1'),
			'#circle2#' => $this->_buildSymbolImgTag('circle2'),
			'#circle3#' => $this->_buildSymbolImgTag('circle3'),
			'#square1#' => $this->_buildSymbolImgTag('square1'),
			'#square2#' => $this->_buildSymbolImgTag('square2'),
			'#diamond1#' => $this->_buildSymbolImgTag('diamond1'),
			'#diamond2#' => $this->_buildSymbolImgTag('diamond2'),
			'#triangle1#' => $this->_buildSymbolImgTag('triangle1'),
			'#triangle2#' => $this->_buildSymbolImgTag('triangle2'),
			'#triangle3#' => $this->_buildSymbolImgTag('triangle3'),
			'#triangle4#' => $this->_buildSymbolImgTag('triangle4')
		);
		return str_ireplace(array_keys($replacements), array_values($replacements), $str);
	}

	/**
	 * @param string $symbol
	 * @return string
	 */
	private function _buildSymbolImgTag($symbol)
	{
		$src = sprintf('WSB/XT/Pio/etc/symbols/%s.png', $symbol);
		return sprintf('<img src="%s" alt="" width="11" height="12" />', $src);
	}

}